package org.xxforest.game.core.scenes.scene2d;

import org.xxforest.game.core.common.XXDisposable;

public class XXPointerTouch implements XXDisposable{

	private float fromX , fromY ;
	private float toX , toY ;
	private float upX , upY ;
	private float offSetX , offSetY ;
	private int pointer ,button ;
	private XXScreen screen ;
	private XXNode focusActor ;
	private float deltaTime ;
	private boolean touchDown ;
	
	public static XXPointerTouch create() {
		return new XXPointerTouch();
	}

	public void touch(XXScreen screen , XXNode actor , float fromX, float fromY, int pointer, int button) {
		this.focusActor = actor ;
		this.screen = screen ;
		this.fromX = fromX ;
		this.fromY = fromY ;
		this.toX = fromX ;
		this.toY = fromY ;
		this.pointer = pointer ;
		this.button = button ;
		this.touchDown = true ;
	}

	public void drag(float toX, float toY, int pointer) {
		this.offSetX = this.toX - toX;
		this.offSetY = this.toY - toY;
		this.toX = toX ;
		this.toY = toY ;
		this.pointer = pointer ;
	}

	public void touchUp(float upX, float upY, int pointer) {
		this.upX = upX ;
		this.upY = upY ;
		this.pointer = pointer ;
		this.touchDown = false ;
		this.deltaTime = 0 ;
	}

	public float getUpX() {
		return upX;
	}

	public float getUpY() {
		return upY;
	}

	public float getFromX() {
		return fromX;
	}

	public float getFromY() {
		return fromY;
	}

	public float getToX() {
		return toX;
	}

	public float getToY() {
		return toY;
	}

	public int getPointer() {
		return pointer;
	}

	public int getButton() {
		return button;
	}
	
	public float getOffSetX() {
		return offSetX;
	}

	public float getOffSetY() {
		return offSetY;
	}

	@Override
	public void dispose() {
	}

	public XXNode getFocusNode() {
		return this.focusActor;
	}

	public XXScreen getScreen() {
		return screen;
	}
	
	public void alterDeltaTime(float delta){
		this.deltaTime += delta ;
	}
	
	public float getDeltaTime(){
		return this.deltaTime ;
	}
	
	public void resetDeltaTime(){
		this.deltaTime = 0 ;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("XXPointerTouch [fromX=");
		builder.append(fromX);
		builder.append(", fromY=");
		builder.append(fromY);
		builder.append(", toX=");
		builder.append(toX);
		builder.append(", toY=");
		builder.append(toY);
		builder.append(", upX=");
		builder.append(upX);
		builder.append(", upY=");
		builder.append(upY);
		builder.append(", offSetX=");
		builder.append(offSetX);
		builder.append(", offSetY=");
		builder.append(offSetY);
		builder.append(", pointer=");
		builder.append(pointer);
		builder.append(", button=");
		builder.append(button);
		builder.append(", focusActor=");
		builder.append(focusActor);
		builder.append("]");
		return builder.toString();
	}
	
	public boolean isTouchDown() {
		return touchDown;
	}

}
